function searchMenu(searchKey){
	if(searchKey == "" || searchKey == null){
		document.getElementById("searchCount").innerHTML='<b>"'+searchKey+'"</b>:搜索出<b>0</b>条记录!';
		document.getElementById("hitArea").innerHTML="";
		return;
	}
		
	var count = 0;
	var hitHtml = "<ul>";
	eval("var reg=/"+searchKey+"/i")
	
	$("#menu1Content").find("a").each(function(){
		var $m1 = $(this);
		var m1Id = $m1.attr("id");
		var m1tx = $m1.text();
		var ret = m1tx.match(reg);
		if(ret != null){
			count++;
			m1tx = m1tx.replace(reg,"<span>"+ret[0]+"</span>");
			hitHtml += "<li>" + m1tx + "</li>";
		}
		
		$("#tb"+m1Id).find("a").each(function(){
			var $m2 = $(this);
			var m2Id = $m2.attr("id");
			var drm2Id = 'dr'+m2Id;
			var m2tx = $m2.text();
			var ret = m2tx.match(reg);
			var $m2chd = $("#"+drm2Id).find("a");
			if(ret != null){
				count++;
				m2tx = m2tx.replace(reg,"<span>"+ret[0]+"</span>");
				if($m2chd.length == 0){
					m2tx = '<a href="javascript:" onclick="$(\'#'+m2Id+'\').click();">' + m2tx + '</a>';
				}
				hitHtml += "<li>" + m1tx + " -> " + m2tx + "</li>";
			}
			
			$m2chd.each(function(){
				var $m3 = $(this);
				var m3Id = $m3.attr("id");
				var drm3Id = 'dr'+m3Id;
				var m3tx = $m3.text();
				var ret = m3tx.match(reg);
				var $m3chd = $("#"+drm3Id).find("a");
				if(ret != null){
					count++;
					m3tx = m3tx.replace(reg,"<span>"+ret[0]+"</span>");
					if($m3chd.length == 0){
						m3tx = '<a href="javascript:" onclick="$(\'#'+m3Id+'\').click();">' + m3tx + '</a>';
					}
					hitHtml += "<li>" + m1tx + " -> " + m2tx + " -> " + m3tx + "</li>";
				}
				
				$m3chd.each(function(){
					var $m4 = $(this);
					var m4Id = $m4.attr("id");
					var m4tx = $m4.text();
					var ret = m4tx.match(reg);
					if(ret != null){
						count++;
						m4tx = m4tx.replace(reg,"<span>"+ret[0]+"</span>");
						m4tx = '<a href="javascript:" onclick="$(\'#'+m4Id+'\').click();">' + m4tx + '</a>';
						hitHtml += "<li>" + m1tx + " -> " + m2tx + " -> " + m3tx + " -> " + m4tx + "</li>";
					}
				})
			})
		})
	})
	hitHtml += "</ul>";
	document.getElementById("hitArea").innerHTML=hitHtml;
	document.getElementById("searchCount").innerHTML='<b>"'+searchKey+'"</b>:搜索出<b>'+ count +'</b>条记录!';
	$("#searchBox").show();
}

$(document).ready(function() {
	
	$(".sub_menu").bgiframe();
	$("#searchBox").bgiframe();

	$("#searchText").bind("keydown", function(e){
		if(e.keyCode == 13){
			searchMenu(this.value);
		}
	});

	$("#searchBtn").bind("click",function(){
		searchMenu(document.getElementById("searchText").value);
	});

	$("#searchHead").mousedown(function(e){
		var x = $("#searchBox").offset().left - e.pageX;
		var y = $("#searchBox").offset().top - e.pageY;
		$(document).bind("mousemove", function(e){
			$("#searchBox").offset({left:e.pageX + x, top:e.pageY + y});
		});
	}).mouseup(function(){
		$(document).unbind("mousemove");
	});
	$("#closeSearch").click(function(){
		$("#searchBox").hide();
	});

	menuload();
	var mu1 = new Slider("menu2Ctr", "menu2Sdr", 0, { Vertical: true, Auto:false, Duration:0});
	mu1.Run();

	taskBar.init("taskBar", "mainframe");
	try{
		document.getElementById("m_0_0_0_0").click();
	}catch(e){
		try{
			document.getElementById("m_0_0_0").click();
		}catch(e){
			$("#m_0_0").click();
		}
	}
	//taskBar.createWin('work','工作台','js6/FN90001/TXdemo_V1.2.htm');

	//侧边栏滑动
	var sidelink = new Slider("sideLinkCtr", "sideLinkSdr", 0, { Vertical: false, Auto:false, Duration:15});
	window.sidelink = sidelink;
	sidelink.Run();
	$("#sbLinkRight").click(function(){
		sidelink.Next();
	});
	$("#sbLinkLeft").click(function(){
		sidelink.Previous();
	});

	//侧边栏移动
	$("#sidebarMain").css("visibility", "visible");
	$("#sidebarMain").hide();
	$("#sbhandOff").click(function(){
		$("#sbhandOff").hide();
		$("#sidebarMain").stop();
		$("#sidebarMain").show().animate({left:"-200px"}, 200);
	})
	$("#sidebarMain").mouseleave(function(){
		$("#sidebarMain").stop();
		$("#sidebarMain").animate({left:"27px"}, 200, function(){
			$(this).hide();
			$("#sbhandOff").show();
		});
	});

	$("#menu1Content").find("a").each(function(i){
		var $m1 = $(this);
		var m1Id = $m1.attr("id");
		
		$m1.bind("click", function(){
			//if(bn)return;
			mu1.Run(i);
			$(".menu1_on").removeClass("menu1_on");
			$(this).addClass("menu1_on")
		});
		
		var mu2 = new Slider("ct"+ m1Id, "tb" + m1Id, 0, { Vertical: false, Auto:false, Duration:30, Warp:false, isLevelTwo:true, onStart:function(){
			if(this.Index <= 0){
				$("#l"+m1Id).css("visibility","hidden");
			}else{
				$("#l"+m1Id).css("visibility","visible");
			}
			
			if(this.Index >= (this._count - 1)){
				$("#r"+m1Id).css("visibility","hidden");
			}else{
				$("#r"+m1Id).css("visibility","visible");
			}
		}});
		if(mu2._count > 1){
			$("#l"+m1Id).click(function(){
				mu2.Previous();
			}).css("visibility","hidden");
			$("#r"+m1Id).click(function(){
				mu2.Next();
			}).css("visibility","visible");
		}
		
		var m2CCBMenus = [];
		$("#tb"+m1Id).find("a").each(function(i){
			var $m2 = $(this);
			var m2Id = $m2.attr("id");
			var drm2Id = 'dr'+m2Id;
			if(document.getElementById(drm2Id) == null) return;
			var m2CCBMenu = new CCBMenu(m2Id, drm2Id, true, null, m2CCBMenus);
			m2CCBMenus.push(m2CCBMenu);
			m3CCBMenus = [];
			
			$("#"+drm2Id).find("a").each(function(i){
				var $m3 = $(this);
				var m3Id = $m3.attr("id");
				var drm3Id = 'dr'+m3Id;
				if(document.getElementById(drm3Id) == null) return;
				var m3CCBMenu = new CCBMenu(m3Id, drm3Id, false, m2CCBMenu, m3CCBMenus);
				m3CCBMenus.push(m3CCBMenu);
			});
		});
	});

	$("#menu2Ctr").css("visibility","visible");
	
	$('#arrow_right,#text_left').click(function(e){
		$('.list').toggle();
		if($$B.ie6 || $$B.ie7){
			$('.list').css("margin-left","0px")
			$('.list').css("left", $("#text_left").offset().left + 43 + "px");
		}
		e.stopPropagation();
		$('body').click(function(){
				$('.list').hide();
		});	
	});
	
	$('.list li').click(function(){
		$('#text_left').text(($(this).text()));  
	});
	
	$("#sbMenuHelp").click(function(){
		var menuHelpDiv = document.getElementById("menuHelpDiv");
		var menuHelpImg = document.getElementById("menuHelpImg");
		if(menuHelpDiv.style.display=="none"){
			menuHelpDiv.style.display = "block";
			menuHelpImg.style.display = "block";
			var imgleft = (document.documentElement.clientWidth - menuHelpImg.width) / 2;
			menuHelpImg.style.left = imgleft > 0? imgleft+"px" : "0px";
		}
	});
	
	$("#menuHelpDiv").click(function(){
		var menuHelpImg = document.getElementById("menuHelpImg");
		if(this.style.display=="block"){
			this.style.display = "none";
			menuHelpImg.style.display = "none";
		}
	});
	$("#menuHelpImg").click(function(){
		var menuHelpDiv = document.getElementById("menuHelpDiv");
		if(menuHelpDiv.style.display=="block"){
			this.style.display = "none";
			menuHelpDiv.style.display = "none";
		}							 
	});
		   

	//reorderMenu('m_16,m_15,m_14,m_13,m_12,m_11,m_10,m_9,m_8,m_7,m_6,m_5,m_4,m_3,m_2,m_1');
	//var eTime = (new Date()).getTime();
	//alert(eTime - sTime);
})